package com.systop.supervise.controller;
import com.systop.common.pojo.Teacher;
import com.systop.common.util.ResponseResult;
import com.systop.supervise.service.TeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
public class SupTeacherController {

    @Autowired
    private TeacherService teacherService;
    /*
    * supervice登陆
    * csh
    * */
    @ApiOperation(value="login", notes="login")
    @RequestMapping(value = "/superviseLogin",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult getAdmin(String tno , String password){
            Teacher tea = new Teacher();
            tea.setTno(tno);
            tea.setPassword(password);
            Teacher teacher = teacherService.SudentLogin(tea);
            if (teacher == null){
                return  ResponseResult.build(500,"登陆失败");
            }else{
                return  ResponseResult.build(200,"登陆成功",teacher);
            }
    }

    /*
     * supervise 查看全部
     * csh
     * */
   @ApiOperation(value="查看全部", notes="查看全部")
    @RequestMapping(value = "/teacherSupList",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult teacherSupList1(){
        List<Teacher> tealist = teacherService.teacherSupList();
	
        if (tealist == null){
            return  ResponseResult.build(500,"失败");
        }else{
            return  ResponseResult.build(200,"查看成功",tealist);
        }
    }

    /*
     * supervise 添加teacher的信息
     * csh
     * */
    @ApiOperation(value="添加teacher的信息", notes="添加teacher的信息")
    @RequestMapping(value = "/insertSupervice",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult insertSupervice1(@RequestParam(value = "tno")String tno,@RequestParam(value = "name")String name, @RequestParam(value = "college_name")String college_name, @RequestParam(value = "password")String password,@RequestParam(value = "professional")String professional,@RequestParam(value = "sex")String sex,@RequestParam(value = "phone_url")String phone_url,@RequestParam(value = "type")String type,@RequestParam(value = "remark")String remark){
     //  System.out.println("-----------------------------"+teacher.getName()+"------------------------------------");
        Teacher teacher = new Teacher();
        teacher.setTno(tno);
        teacher.setName(name);
        teacher.setCollege_name(college_name);
        teacher.setPassword(password);
        teacher.setProfessional(professional);
        teacher.setSex(sex);
        teacher.setPhone_url(phone_url);
        int type1 = Integer.parseInt(type);
        teacher.setType(type1);
        teacher.setRemark(remark);
        int i = teacherService.insertSupervice(teacher);
        if (i == 0){
            return  ResponseResult.build(500,"失败");
        }else{
            return  ResponseResult.build(200,"添加成功",i);
        }
    }

    /*
     * supervise 通过String tno 查看 teacher的信息
     * csh
     * */
    @ApiOperation(value="通过String tno 查看 teacher的信息", notes="通过String tno 查看 teacher的信息")
    @RequestMapping(value = "/updataSupervice1",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult teacherSupteacher1(@RequestParam(value = "tno") String tno){
        List<Teacher> list= teacherService.teacherSupteacher(tno);
        if (list == null){
            return  ResponseResult.build(500,"失败");
        }else{
            return  ResponseResult.build(200,"通过tno查成功",list);
        }
    }

    /*
     * supervise 修改teacher的信息
     * csh
     * */
    @ApiOperation(value="修改teacher的信息 ", notes="修改teacher的信息")
    @RequestMapping(value = "/updataSupervice",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult updataSupervice1(@RequestParam(value = "tno")String tno, @RequestParam(value = "name")String name, @RequestParam(value = "college_name")String college_name, @RequestParam(value = "password")String password, @RequestParam(value = "professional")String professional, @RequestParam(value = "sex")String sex, @RequestParam(value = "phone_url")String phone_url, @RequestParam(value = "type")String type, @RequestParam(value = "remark")String remark){
        Teacher teacher = new Teacher();
        teacher.setTno(tno);
        teacher.setName(name);
        teacher.setCollege_name(college_name);
        teacher.setPassword(password);
        teacher.setProfessional(professional);
        teacher.setSex(sex);
        teacher.setPhone_url(phone_url);
        int type1 = Integer.parseInt(type);
        teacher.setType(type1);
        teacher.setRemark(remark);
        int i= teacherService.updataSupervice(teacher);
        if (i == 0){
            return  ResponseResult.build(500,"失败");
        }else{
           return  ResponseResult.build(200,"成功",i);
        }
    }
    /*
     * supervise 删除teacher的信息
     * csh
     * */
    @ApiOperation(value="删除teacher的信息 ", notes="删除teacher的信息")
    @RequestMapping(value = "/deleteSupervice",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult deleteTeacher1(String tno){
        int i = teacherService.deleteTeacher(tno);
        if (i == 0){
            return  ResponseResult.build(500,"失败");
        }else{
            return  ResponseResult.build(200,"成功",i);
        }
    }


}
